package com.wgke.bluetooth.tools;

import android.bluetooth.BluetoothDevice;

public class BlueToothBean {
    //获取设备的友好名称（可能为 null）
    private String name;
    private String d;
    // MAC 地址（格式："00:11:22:AA:BB:CC"）
    private String address;
    private String id;

    private int rssi;//信号强肉

    //BluetoothDevice.DEVICE_TYPE_CLASSIC (1) - 传统蓝牙设备
    //BluetoothDevice.DEVICE_TYPE_LE (2) - 仅低功耗蓝牙设备
    //BluetoothDevice.DEVICE_TYPE_DUAL (3) - 双模设备
    //BluetoothDevice.DEVICE_TYPE_UNKNOWN (0) - 未知类型
    private String type;

    //BOND_NONE (10) - 未配对
    //BOND_BONDING (11) - 正在配对
    //BOND_BONDED (12) - 已配对
    private String status;
    //ADDRESS_TYPE_PUBLIC (0) - 公共地址
    //ADDRESS_TYPE_RANDOM (1) - 随机地址
    //ADDRESS_TYPE_UNKNOWN (-1) - 未知类型
    private String addressType;

    private int majorDeviceClass;

    public int getMajorDeviceClass() {
        return majorDeviceClass;
    }

    public void setMajorDeviceClass(int majorDeviceClass) {
        this.majorDeviceClass = majorDeviceClass;
    }

    public String getAddressType() {
        return addressType;
    }

    public void setAddressType(String addressType) {
        this.addressType = addressType;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public static BlueToothBean get(String name, String address) {
        BlueToothBean bean = new BlueToothBean();
        bean.setAddress(address);
        bean.setName(name);
        return bean;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getRssi() {
        return rssi;
    }

    public void setRssi(int rssi) {
        this.rssi = rssi;
    }

    public String rssiToString() {
        //-50dBm 到 -30dBm: 信号极强，距离很近
        if (-50 <= rssi && rssi <= -30) {
            return "信号极强，距离很近;";// + rssi + "dBm";
        }
        //-70dBm 到 -50dBm: 信号良好
        if (-70 <= rssi && rssi <= -50) {
            return "信号良好;";// + rssi + "dBm";
        }
        //-85dBm 到 -70dBm: 信号一般
        if (-85 <= rssi && rssi <= -70) {
            return "信号一般;";//+ rssi + "dBm";
        }
        //-100dBm 以下: 信号很差，可能断开连接
        if (rssi < -85) {
            return "信号很差，可能断开;";// + rssi + "dBm";
        }
        return "" + rssi + "dBm";
    }

    public String typeToString() {
        try {
            int t = Integer.parseInt(this.type);
            switch (t) {
                case BluetoothDevice.DEVICE_TYPE_CLASSIC:
                    return "传统蓝牙";
                case BluetoothDevice.DEVICE_TYPE_LE:
                    return "BLE设备";
                case BluetoothDevice.DEVICE_TYPE_DUAL:
                    return "双模设备";
                default:
                    return "未知类型";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "未知类型";
    }

    public static final int MISC = 0x0000;
    public static final int COMPUTER = 0x0100;
    public static final int PHONE = 0x0200;
    public static final int NETWORKING = 0x0300;
    public static final int AUDIO_VIDEO = 0x0400;
    public static final int PERIPHERAL = 0x0500;
    public static final int IMAGING = 0x0600;
    public static final int WEARABLE = 0x0700;
    public static final int TOY = 0x0800;
    public static final int HEALTH = 0x0900;
    public static final int UNCATEGORIZED = 0x1F00;

    public String toMajorDeviceClassString() {
        switch (getMajorDeviceClass()) {
            case MISC:
                return "Miscellaneous";//杂项/其他设备
            case COMPUTER:
                return "Computer";//电脑设备
            case PHONE:
                return "Phone";//手机
            case NETWORKING:
                return "Networking Device";
            case AUDIO_VIDEO:
                return "Audio/Video Device";
            case PERIPHERAL:
                return "Peripheral";
            case IMAGING:
                return "Imaging Device";
            case WEARABLE:
                return "Wearable";//智能手表等穿戴设备
            case TOY:
                return "Toy";
            case HEALTH:
                return "Health Device";//心率监测器等健康设备
            case UNCATEGORIZED:
                return "Uncategorized";//厂商自定义设备
            default:
                return "Unknown";
        }
    }
}
